import { fetchGet,fetchPost,fetchDelete,fetchPut,fetchPatch} from '../utils/http'
import { BASE_URL } from '../utils/host'

/**
 * 登入
 */
export const login = (params) => {
    return fetchPost("/login",{
        username:params.username,
        password:params.password,
        client_id:"client",
        client_secret:"secret",
        grant_type:"password"
    })
}

/**
 * 退出登入
 */
export const logout = (params) => {
    return fetchDelete("/user/logout",params)
}

/**
 * 注册
 */
export const register = (params) => {
    return fetchPost("/user/register",{
        email:params.email,
        password:params.password,                                        
        userName:params.userName
    })
}

/**
 * 查询消息设置
 */
export const getMessageConfig = () => {
    return fetchGet("/compuser/config")
}

/**
 * 修改消息设置
 */
export const modifyMessageConfig = (params) => {
    return fetchPatch("/compuser/config",params)
}

/**
 * 修改邮箱
 */
export const modifyEmail = (params) => {
    return fetchPatch("/user/email",{
        email:params.email,
        password:params.password
    })
}

/**
 * 修改密码
 */
export const modifyPassword = (params) => {
    return fetchPut("/user/password",{
        newPassword:params.newPassword,
        oldPassword:params.oldPassword
    })
}

/**
 * 用户个人信息
 */
export const getUserInfo = () => {
    return fetchPost("/user/info")
}

/**
 * 更新个人信息
 */
export const updateUserInfo = (params) => {
    return fetchPost("/user/infoUpdate",{
        education:params.education,
        position:params.position,
        working_unit:params.working_unit
    })
}

/**
 * 上传头像
 */
export const submitAvator = () => {
    return `${BASE_URL}/user/imgUpload`
}

/**
 * 用户余额
 */
export const userBalance = () => {
    return fetchGet("/coin/balance/show")
}

/**
 * 充值记录
 */
export const rechargeRecord = () => {
    return fetchGet("/coin/balance/recharge/logs")
}

/**
 * 消费记录
 */
export const expenseRecord = () => {
    return fetchGet("/coin/order/goods")
}

/**
 * 充值
 */
export const recharge = (params) => {
    return fetchPatch("/coin/balance/add",{coinCnt:params})
}

/**
 * 转赠验证码
 */
export const transferVerificationCode = () => {
    return fetchGet("/checkcode/coin/transfer/send")
}

/**
 * 申请转赠
 */
export const applyTransfer = (params) => {
    return fetchPost("/coin/transfer/apply",{
        checkCode:params.checkCode,
        recipientEmail:params.recipientEmail,
        transferCoin:params.transferCoin
    })
}

/**
 * 转赠确定或取消
 */
export const whetherTransfer = (params) => {
    return fetchPost("/coin/transfer/handle",{
        applyNum:params.applyNum,
        operateType:params.operateType
    })
}

/**
 * 我的课程 
 */
export const getBoughtCourseList = () => {
    return fetchGet("/course/boughtCourse")
}

/**
 * 我的项目
 */
export const getProjectList = () => {
    return fetchGet("/resource/taskAllList")
}

/**
 * 资源配额
 */
export const quotaCheck = () => {
    return fetchGet("/resource/quotaCheck")
}


/**
 * 我的项目查看任务
 */
export const projectView = (params) => {
    return fetchGet("/resource/view",{taskId:params})
}

/**
 * 我的项目分享 
 */
export const projectShare = (params) => {
    return fetchGet("/resource/share",{
        personal:0,
        taskId:params
    })
}

 /**
 * 我的项目释放机器
 */
export const projectRelease = (params) => {
    return fetchGet("/resource/release",{
        commit:params.commit,
        taskId:params.taskId
    })
}

 /**
 * 我的项目删除
 */
export const projectDelete = (params) => {
    return fetchGet("/resource/deletetask",{taskId:params})
}

/**
 * 竞赛详情 
 */
export const getUserCompetitonList = () => {
    return fetchGet("/competition/userCompetition")
}

/**
 * 获取数据集列表
 */
export const getDataList = () => {
    return fetchGet("/data/mylist")
}